package com.cjzuji.rental.controller.order;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.cjzuji.rental.mapper.OrderMapper;
import com.cjzuji.rental.mapper.RequestMapper;
import com.cjzuji.rental.pojo.RequestHeard;
import com.cjzuji.rental.service.QianLianYPService;
import com.cjzuji.rental.service.WsErYpService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/order/ypwser")
@Api(tags = "优品稳实二店")
//@Component
public class WsErYpController {


    @Autowired
    OrderMapper orderMapper;
    @Autowired
    RequestMapper requestMapper;
    @Autowired
    WsErYpService wsErYpService;

    private static final Logger logger = LoggerFactory.getLogger(WsErYpController.class);

    //所有数据
    @GetMapping("/ypwserlist")
    @ApiOperation(value = "获取所有优品稳实二店订单", notes = "优品稳实二店所有订单列表")
    //@Scheduled(fixedRate = 60 * 60 * 2000)
    public List<Map<String, Object>> getOrderList() {
        //从数据库获取
        try {
            QueryWrapper<RequestHeard> queryWrapper = new QueryWrapper<>();
            RequestHeard requestHeard = requestMapper.selectOne(queryWrapper);
            String accesstoken = requestHeard.getWserypaccesstoken();
            String authorization = requestHeard.getWserypauthorization();
            List<Map<String, Object>> result = wsErYpService.getOrderssList(accesstoken, authorization);
            return result;
        } catch (Exception e) {
            logger.error("获取 优品稳实二店 所有订单失败");
            return null;
        }
    }

    //获取租用中的数据
    @PutMapping("/upDateBill")
    @ApiOperation(value = "获取稳实二店租用中的订单", notes = "优品稳实二店正在租用的订单列表")
    //@Scheduled(fixedRate = 60 * 60 * 2000)
    public List<Map<String, Object>> upDateBill(){
        //从数据库获取
        try {
            QueryWrapper<RequestHeard> queryWrapper = new QueryWrapper<>();
            RequestHeard requestHeard = requestMapper.selectOne(queryWrapper);
            String accesstoken = requestHeard.getWserypaccesstoken();
            String authorization = requestHeard.getWserypauthorization();
            List<Map<String, Object>> result = wsErYpService.upDateBillList(accesstoken, authorization, "useList");
            return result;
        }catch (Exception e){
            logger.error("获取 优品稳实二店 正在租用的订单失败");
            return null;
        }
    }
}
